package com.hxzy.shop.order.config;

import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;


public class CustomerDoubleSerialize extends JsonSerializer<BigDecimal> {

    //原本这里是  ##.00 ,带来的问题是如果数据库数据为0.00返回“ .00 “经评论指正，改为0.00
    private DecimalFormat df = new DecimalFormat("0.00");


    @Override
    public void serialize(BigDecimal bigDecimal, org.codehaus.jackson.JsonGenerator jsonGenerator, org.codehaus.jackson.map.SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
        if(bigDecimal != null && !"".equals(bigDecimal)) {
            jsonGenerator.writeString(df.format(bigDecimal));
        }

//        else {
//            jsonGenerator.writeString(bigDecimal + "");
//        }
    }
}